package mylab.usm.oauth2.client.config;

import com.google.common.collect.Maps;
import lombok.Data;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.util.Map;

/**
 * @Description:
 * @author: Sylar
 * @date: 2021年12月03日 2:36 下午
 */
@Getter
@ConfigurationProperties(prefix = AuthProperties.PREFIX)
public class AuthProperties {
    public final static String PREFIX = "auth";

    /**
     * 是否启用sso
     */
    private boolean sso = false;

    /**
     * 应用服务的根域名
     */
    private String domain = "jap.com";

    /**
     * 认证配置信息
     */
    @NestedConfigurationProperty
    private Map<String, Platform> platforms = Maps.newHashMap();


    @Data
    public static class Platform {
        //@formatter:off
        private String platformId           = "jai";
        private String issuer               = "http://localhost:8081";
        private String clientId             = "zehtufcp4v3zs8nzs2ldp7hkd22y00t9";
        private String clientSecret         = "8dnf2r7diltoj1nx98iix0ydbayldq3c1wg00006";
        private String authorizationUrl     = issuer + "/oauth/authorize";
        private String tokenUrl             = issuer + "/oauth/token";
        private String userinfoUrl          = issuer + "/oauth/userinfo";
        private String[] scopes             = new String[]{"read", "write"};

        /**
         * 回调地址，是本应用的地址，用来接收第三方平台的授权码等信息
         */
        private String callbackUrl          = "http://sso.${auth.domain}:${server.port}/oauth2/login/" + platformId;

        /**
         * 不同的 oauth 平台用户id都不一样, 此处标识第三方平台用户信息中的用户id字段
         */
        private String uidField             = "userId";

        //@formatter:on

        /**
         * 仅OAuth密码模式需要
         */
        private String username;
        /**
         * 仅OAuth密码模式需要
         */
        private String password;


    }

}
